package hn.sigit.model.hnd.cadastre;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="HND_LandUse", schema="hnd_cadastre")
@Inheritance(strategy=InheritanceType.JOINED)
public class HND_LandUse implements Serializable {
	private static final long serialVersionUID = -25359761903060860L;

	private Long id;
	private String code;
	private String subCode;
	private String completeCode;
	private String name;
	private int level;
	private HND_LandUseType type;
	private boolean leaf;
	
	private HND_LandUse parent;
	private java.util.Set<HND_LandUse> childs = new java.util.HashSet<HND_LandUse>();


	@Id
	@Column(name="ID", nullable=false)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="hnd_landuseclasification_id_gen")
	@SequenceGenerator(name="hnd_landuseclasification_id_gen", sequenceName="hnd_landuseclasification_id_seq", allocationSize=1)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	
	@Column(name="code", nullable=false)
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	
	@Column(name="subCode", nullable=true)
	public String getSubCode() {
		return subCode;
	}
	public void setSubCode(String subCode) {
		this.subCode = subCode;
	}
	
	
	@Column(name="completeCode", nullable=false)
	public String getCompleteCode() {
		return completeCode;
	}
	public void setCompleteCode(String completeCode) {
		this.completeCode = completeCode;
	}
	
	
	@Column(name="name", nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	@Column(name="level", nullable=false)
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	
	
	@Column(name="type", nullable=false)
	@Enumerated(EnumType.STRING)
	public HND_LandUseType getType() {
		return type;
	}
	public void setType(HND_LandUseType type) {
		this.type = type;
	}
	
	
	@Column(name="leaf", nullable=false)
	public boolean isLeaf() {
		return leaf;
	}
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	
	@ManyToOne(targetEntity=HND_LandUse.class, fetch=FetchType.LAZY)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})	
	@JoinColumns({ @JoinColumn(name="HND_LandUseID", referencedColumnName="ID") })	
	@org.hibernate.annotations.LazyToOne(value=org.hibernate.annotations.LazyToOneOption.NO_PROXY)	
	public HND_LandUse getParent() {
		return parent;
	}
	public void setParent(HND_LandUse parent) {
		this.parent = parent;
	}
	
	@OneToMany(mappedBy="parent", targetEntity=HND_LandUse.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<HND_LandUse> getChilds() {
		return childs;
	}
	public void setChilds(java.util.Set<HND_LandUse> childs) {
		this.childs = childs;
	}
	
	@Transient
	public String getFullName() {
		return String.format("%s - %s", getCompleteCode(), getName());
	}

}
